#!/bin/env python
#-*- coding:utf-8 -*-
########################################
#Author:林波1278                       #
#Date:2015.11.10                       #
#E-mail:qingbo.song@apicloud.com       #
#Comment: login_passwd.py              #
#Path:                                 #
#Version:V 1.0                         #
########################################

import os,sys

userName = "qingbo"
userPasswd = "test"
flag = False
userBlackPath = "./user_back.txt"

def UserBlack():
	if os.path.exists(userBlackPath):
		fileUsers = open(userBlackPath)
		userBlack = fileUsers.read()
		fileUsers.close()
		if userName == userBlack:
			print "Sorry,your name is in the blacklist,Please to connet the admin!"
			sys.exit(1)


def Login(passwd):
	'''用户登录接口函数'''
	UserBlack();
	while True:
		users = raw_input("users:").strip()
		passwd = raw_input("passwd:").strip()
		if users == userName:
			if passwd == userPasswd:
				Welcome("True");
				sys.exit(0)
			else:
				Welcome("Error");
				break
		else:
			Welcome("False");


def Welcome(loginFlag):
	'''欢迎信息页面'''
	if loginFlag == "True":
		print "Welcome login the System!"
	if loginFlag == "Error":
		print "Sorry,your passwd is Error!"
	if loginFlag == "False":
		print "Sorry,your userName is not have!"

for i in xrange(3):
	Login("passwd");
if flag == False:
	print "Your name is now to add the blacklist!"
	fileUsers = open(userBlackPath,"w")
	fileUsers.write(userName)
	fileUsers.close()
	sys.exit(0)